import request from "@/utils/requset";
import store from "@/store";
// console.log(`localStorage = Bearer +${localStorage.getItem("token")}`);
// console.log(`store = Bearer + ${store.state.token}`);

// 获取导航栏
const getHomeChannelListAPI = () =>
  request({
    url: "/v1_0/user/channels",
    method: "get",
    headers: {
      //   Authorization: `Bearer +${localStorage.getItem("token")}`,
      Authorization: `Bearer ${store.state.token}`,
    },
  });

// 获取新闻内容
const getAllArticles = (channel_Id, timestamp = Date.now()) => {
  // console.log(channel_Id);
  return request({
    url: `/v1_0/articles`,
    method: "GET",
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`,
    // },
    params: { channel_id: channel_Id, timestamp: timestamp },
  });
};

//不喜欢文章
const dislikeArticle = (id) => {
  // console.log(id);
  return request({
    url: "/v1_0/article/dislikes",
    method: "POST",
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`,
    // },
    data: { target: id },
  });
};

// 举报文章

const reportsAtricle = (id, type) => {
  return request({
    url: "/v1_0/article/reports",
    method: "POST",
    // headers: {
    //   Authorization: `Bearer ${store.state.token}`,
    // },
    data: {
      target: id,
      type: type,
      remark: `举报文章`,
    },
  });
};
// 添加频道后更新频道
const setChannel = (channels) => {
  return request({
    url: "/v1_0/user/channels",
    method: "put",
    data: { channels },
  });
};

// 删除频道
const deleteChannel = (id) => {
  request({
    url: `/v1_0/user/channels/${id}`,
    method: "DELETE",
  });
};

export {
  getHomeChannelListAPI,
  getAllArticles,
  dislikeArticle,
  reportsAtricle,
  setChannel,
  deleteChannel,
};
